package com.hopedove.tempdemo.net.data

import com.google.gson.JsonElement

data class ProductionNoticeDetail(
    var TCTZDBH: String?,
    var GJUPH: String?,
    var PZYQ: String?,
    var MLZYSX: String?,
    var REMARK: String?,
    var DHYQPZYN: String?,
    var DWEIGHT: Int?,
    var CRENAME: String?,
    var MACHINETYPE: String?,
    var FHBMX: String?,
    var BH: String?,
    var LINELENGTH: String?,
    var DHYQPZ: String?,
    var PINTOTAL: String?,
    var MPZYYQ: String?,
    var CLOTHNAME: String?,
    var ENDPROWEIGHT: Int?,
    var MHOLES: String?,
    var MNO: String?,
    var JSFS: String?,
    var THSM: String?,
    var ENDPROWIDTH: String?,
    var DHYQPZXM: String?,
    var DWIDTH: String?,
    var GYKBBH: String?,
    var CLOTHNO: String?,
    var DHYQPZBL: String?,
    var JZBL: String?,
    var NEEDARRGMT: String?,
    var ARRGMENTREMARK: String?,
    var MLZFM: String?,
    var QTYREMARK: String?,
    var CRETIME: String?,
    var TCDBBH: String?,
    var PZ: String?
) {


    fun clothYarnRequire(): String {
        return MPZYYQ?.replace("<br/>", "") ?: ""
    }
}

data class GetProductionNoticeResponse(
    var rst: ProductionNoticeDetail?,
    var rst_zzpl: NeedleKnitArrangeBaseInfo?,
    var zzpl: List<NeedleKnitArrangeItem>?,
    var rst_sjpl: TriangleArrangeBaseInfo?,
    var sjpl: List<TriangleArrangeItem>?,
    var jsinfo: List<TriangleArrangeArrayItem>?,
    var rst_yjt: ArtDesignInfo?,
    var yjt: List<ArtDesignItem>?,
    var dsMap: Map<String, JsonElement?>?,
    var ds: JsonElement,
    var mhList: JsonElement,
    var mlremark: String?,
    var gjh: String?,
    var hyhs: String?,
    var gydid: String?,
    var cthyhs: String?,
    var gj: String?,
    var rzgy: String?,
    var printtime: String?
) {

    fun layoutInfoFormat(): String {
        val content = gj ?: return ""
        return content.replace("&nbsp;", " ").replace("<span>", " ").replace("</span>", " ")
            .replace("<br/>", "\n").replace("<BR/>", "\n")
    }

    //
    fun isYarnGrayEmpty(): Boolean {
        if (mhList.isJsonNull) return true
        return mhList.asJsonArray.size() == 0
    }

    fun yarnGrayListFormat(): String {
        val sb = StringBuilder()
        if (!mhList.isJsonNull) {
            mhList.asJsonArray.forEach {
                sb.append(it.asString.replace("<BR/>", "\n")).append("\n")
            }
        }
        return sb.toString()
    }

    // 特殊横条
    fun isSpecialStripeEmpty(): Boolean {
        val dm = dsMap ?: return true
        val specialStripeArr = dm["TSHT"] ?: return true
        if (specialStripeArr.isJsonNull) return true
        return specialStripeArr.asJsonArray.size() == 0
    }

    fun specialStripeFormat(): String {
        if (isSpecialStripeEmpty()) return ""
        var text = ""
        dsMap?.get("TSHT")?.asJsonArray?.forEach {
            if (it.isJsonObject && it.asJsonObject.has("HTNR")) {
                val content =
                    it.asJsonObject.getAsJsonPrimitive("HTNR").asString
                        .replace("<br/>", "\n")
                        .replace("&nbsp;", " ")
                text = if (text.isNotEmpty()) {
                    "${text}\n${content}"
                } else {
                    content
                }
            }
        }

        return text
    }
}
